package com.qf.deadletter;

import com.qf.util.ConnUtil;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import org.junit.Test;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class Publisher {

    @Test
    public void publisher() throws IOException {

        //1. 获取connection对象
        Connection connection = ConnUtil.getConnection();

        //2. 创建Channel对象
        Channel channel = connection.createChannel();

        //3.1 创建死信交换机和死信队列并绑定
        channel.exchangeDeclare("dead_exchange", BuiltinExchangeType.FANOUT);
        channel.queueDeclare("dead_queue",true,false,false,null);
        channel.queueBind("dead_queue","dead_exchange","");

        //3.2 创建普通exchange和普通queue并绑定
        channel.exchangeDeclare("normal_exchange", BuiltinExchangeType.FANOUT);
        Map<String, Object> args = new HashMap<>();
        args.put("x-dead-letter-exchange","dead_exchange");
        args.put("x-message-ttl",10000);
        channel.queueDeclare("normal_queue",true,false,false,args);
        channel.queueBind("normal_queue","normal_exchange","");


        //3.3 发送消息到普通交换机
        channel.basicPublish("normal_exchange","",null,"嘿嘿嘿111".getBytes());



    }


}
